import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { createVNode } from 'vue';
import { Modal } from 'ant-design-vue';
// utils
import { dataTypes } from "@/utils"
const confirmPlug = (params = {}) => {
  Modal.confirm({
    wrapClassName: "confirm-modal",
    title: params?.title || '标题',
    icon: createVNode(ExclamationCircleOutlined),
    content: params?.content || '内容',
    cancelText: params?.cancelText || '取消',
    okText: params?.okText || '确定',
    destroyOnClose: true,
    onOk() {
        const isFunction = dataTypes().isFunction(params.okAsync)
        if(!isFunction) {
            return
        }
        return new Promise((resolve, reject) => {
            params.okAsync().then(() => {
                resolve()
            }).catch(() => {
                reject()
            });
        })
    },
    onCancel() {
      params.cancelAsync && params.cancelAsync()
    },
  });
};

export default confirmPlug